define(['app'], function(app) {
	'use strict';

	//实例化方法
	var factory = function(Http) {
		function get_data_coupon(result) {
			if(false) {
				result = '{"success":true,"msg":"","result":{"coupon":[{"coupon_id":1,"coupon_data":"满100减20"},{"coupon_id":2,"coupon_data":"满100减30"},{"coupon_id":3,"coupon_data":"满100减40"},{"coupon_id":4,"coupon_data":"满100减50"}]},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else
				return result;
		}

		function get_data_ship(result) {
			if(false) {
				result = '{"success":true,"msg":"","result":{"dlytype":[{"id":1,"name":"申通快递(30元)"},{"id":1,"name":"元通快递(40元)"},{"id":1,"name":"中通快递(50元)"}]},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else
				return result;
		}
		function get_data_checkout(result){
			if(false){
				result = '{"success":true,"msg":"订单","result":{"md5_cart_info":"abc","delivery":[{"addr_id":1,"ship_area":"北京市西城区","ship_addr":"北京市西城北区1111号","ship_zip":56789,"ship_name":"李东","ship_mobile":18601579874,"area_id":5,"member_id":123456789},{"addr_id":2,"ship_area":"北京市东城区","ship_addr":"北京市东城南区22222号","ship_zip":56789,"ship_name":"李东","ship_mobile":18601579874,"area_id":5,"member_id":123456789},{"addr_id":3,"ship_area":"桂林市西城区","ship_addr":"桂林市西城北区1111号","ship_zip":56789,"ship_name":"王六","ship_mobile":18601579888,"area_id":5,"member_id":123456789}],"order_detail":{"cost_item":298,"total_amount":198,"totalGainScore":198,"discount_rate":1,"real_usage_point":302,"trigger_tax":true,"tax_ratio":0.2,"no_shipping":true},"order_items":[{"store_id":1,"store_name":"未来五金专卖店1","store_count":50,"store_slip_subtotal":30,"goods_count":1000,"goods_preferentialnumber":100,"coupon":[{"cpns_id":1,"cpns_name":"满100减20","cpns_prefix":1234567},{"cpns_id":2,"cpns_name":"满100减30","cpns_prefix":1234568},{"cpns_id":3,"cpns_name":"满100减40","cpns_prefix":1234569},{"cpns_id":4,"cpns_name":"满100减50","cpns_prefix":1234580}],"payment":[{"id":1,"name":"微信支付","logo":"img/guilin/afsrue/pay01.png"},{"id":2,"name":"支付宝","logo":"img/guilin/afsrue/pay02.png"},{"id":3,"name":"预存款","logo":"img/guilin/afsrue/pay03.png"},{"id":4,"name":"货到付款(授信)","logo":"img/guilin/afsrue/pay04.png"},{"id":6,"name":"线下交易","logo":"img/guilin/afsrue/pay06.png"}],"shipping":[{"id":1,"name":"申通快递","money":"30元"},{"id":2,"name":"元通快递","money":"40元"},{"id":3,"name":"顺丰快递","money":"50元"}],"slips":[{"slip_id":1,"items":[{"ident_id":2,"type":"normal","goods_id":123456,"product_id":234567,"goods_name":"Crocs优雅浅口软皮面小单鞋","spec_info":"颜色：黄色、尺码：34","price":180,"num":1,"image":"img/auction/14_4.jpg"}]}]}]}}';
				return JSON.parse(result);
			}else
			return result;
		}
		function get_data_get_afpy(result){
			if(false){
				result = '{"success":true,"msg":"","result":{"payment":[{"pay_id":"001","pay_name":"微信支付","logo":"img/auction/15_5.jpg","pay_kind":"1"},{"pay_id":"002","pay_name":"支付宝","logo":"img/auction/15_2.jpg","pay_kind":"1"},{"pay_id":"003","pay_name":"预存款","logo":"img/auction/15_3.jpg","pay_kind":"1"},{"pay_id":"004","pay_name":"授信支付","logo":"img/auction/15_4.jpg","pay_kind":"2"},{"pay_id":"005","pay_name":"货到付款","logo":"img/auction/15_3.jpg","pay_kind":"3"},{"pay_id":"006","pay_name":"款到付货","logo":"img/auction/15_3.jpg","pay_kind":"3"},{"pay_id":"007","pay_name":"线下交易","logo":"img/auction/15_3.jpg","pay_kind":"4"}]},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			}else
			return result;
		}
		function get_data_update_total(result){
			if(false){
				result = '{"success":true,"msg":"","result":{"total_amount":512}}';
				return JSON.parse(result);
			}else
			return result;
		}
		//银行
		function get_data_bank_detail(result){
		if(false){
			result = '{"success":true,"msg":"","result":{"id":"001","bank_name":"工商银行","bank_no":"134567890","account_name":"李某某","phone":"126589715"},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
			return JSON.parse(result);
		}else
		return result;
		}
		
		//返回信息
		return {
			//银行
			bank_detail:function(id,callback){
				Http.post({
					method:'member.bankdata.detail',
					id:id
				},function(result){
					if(callback)
					callback(get_data_bank_detail(result).result);
				},function(e){
					
				},function(){
					
				})
			},
			get_ship: function(store_id, order_id, callback) {
				Http.post({
					method: 'cart.get_ship',
					store_id: store_id,
					order_id: order_id

				}, function(result) {
					if(callback)
						callback(get_data_ship(result).result);
				}, function(e) {

				}, function() {

				})
			},
			get_coupon: function(store_id, order_id, callback) {
				Http.post({
					method: 'cart.get_coupon',
					store_id: store_id,
					order_id: order_id
				}, function(result) {
					if(callback)
						callback(get_data_coupon(result).result);
				}, function(e) {

				}, function() {

				})
			},
			get_checkout:function(area_id,status,type,callback){
				Http.post({
					method:'cart.checkout',
					area_id:area_id,
					picSize:'CS',
					status:status,
					type:type
				},function(result){
					console.log(result)
					if(callback)
					callback(get_data_checkout(result).result);
				})
			},
			get_afpay: function(store_id,order_id,callback){
        		Http.post({
        			method:'cart.get_pay',
        			store_id:store_id,
        			order_id:order_id,
        			picSize:'CS'
        		},function(result){
        			if(callback)
        			callback(get_data_get_afpy(result).result);
        		},function(e){
        			
        		},function(){
        			
        		})
        	},
        	create_pay:function(delivery,shipping,invoice_value,md5_cart_info,status,type,tax_company,callback){
        		Http.post({
        			method:'bcart.create',
        			delivery:delivery,
        			shipping:shipping,
        			invoice_value:invoice_value,
        			md5_cart_info:md5_cart_info,
        			status:status,
        			type:type,
        			tax_company:tax_company
        		},function(result){
        			if(callback)
        			callback(result);
        		},function(e){
        			
        		},function(){
        			
        		})
        	},
        	update_total:function(area_id,shipping_id,cpns_id,invoice_value,status,type,callback){
        		Http.post({
        			method:'cart.update_total',
        			area_id:area_id,
        			shipping_id:shipping_id,
        			cpns_id:cpns_id,
        			invoice_value:invoice_value,
        			status:status,
        			type:type,
        		},function(result){
        			if(callback)
        				callback(get_data_update_total(result).result);
        		},function(e){
        			
        		},function(){
        			
        		})
        	},
        	get_address:function(nPage,callback,calldone){
            	Http.post({
            		method:'member.address.getlist',
            		pagelimit:6,
            		nPage:nPage
            		
            	},function(result){
            		if(callback)
            		callback(result.result);
            	},function(){
            		
            	},function(){
            		if(calldone)
            		calldone();
            	})
            },
            get_data: function(type,callack){
				Http.post({
					method:'marketing.seckill.getDate',
					type:type
				},function(result){
					if(callack)
					callack(result.result) ;
				})
			},
			go_pay:function(params,act_id,type,callback){
        		Http.post({
        			method:'marketing.seckill.creatOrder',
        			delivery:params.receiver,
        			shipping:params.shipping,
        			md5_cart_info:params.md5_cart_info,
        			type:type,
        			invoice:params.invoice,
        			purchase:params.purchase,
        			extends_args:params.extends_args,
        			split_order:params.split_order,
        			act_id:act_id,
        			business_goods:params.business_goods
        		},function(result){
        			if(callback)
        			callback(result);
        		},function(e){
        			
        		},function(){
        			
        		})
        	},
        	update_atotal:function(area_id,invoice_type,shipping,shipping_id,store_id,slip_id,split_order,act_type,callback){
        		Http.post({
        			method:'marketing.seckill.shippingChangeSplit',
        			area_id:area_id,
        			invoice_type:invoice_type,
        			store_shipping:shipping,
        			shipping_id:shipping_id,
        			store_id:store_id,
        			slip_id:slip_id,
        			split_order:split_order,
        			act_type:act_type
        		},function(result){
        			if(callback)
        			callback(result);
        		})
        	}
		};
	}

	factory.$inject = ['Http'];
	return app.registerService("Afsrue", factory);
});